<template>
	<div >
	  <div >
		<header>
		  <div class="sn-flex sn-row-center hidden-sm-and-down">
			<el-input v-model="searchValue" placeholder="输入员工名称进行筛选" style="width: 200px" clearable
			  @keyup.enter.native="currentChange(1)" />
			<el-button class="sn-btn" style="margin-left: 10px" type="primary" icon="el-icon-search"
			  @click="currentChange(1)">
			  搜索
			</el-button>
		  </div>
		  <div class="hidden-sm-and-up">
			<el-input v-model="searchValue" placeholder="输入员工名称进行筛选" style="width: 200px" clearable
			  @keyup.enter.native="currentChange(1)" />
			<el-button style="margin-left: 4px" type="primary" class="sn-btn" icon="el-icon-search"
			  @click="currentChange(1)">
			  搜索
			</el-button>
		  </div>
		</header>
		<section>
		  <global-table style="margin-top: 20px;" :showNumber="false"  :headerData="initData"
			:data="tabelData" :isFullScreen="false" :operateW="80">
			<template #isOpen="scope">
				<span >{{scope.row.isOpen?'开启':"关闭"}}</span>
			</template>
			<template #nickname="scope">
				<span >{{scope.row.nickname||''}}{{ scope.row.realname?'('+scope.row.realname+')':''}}</span>
			</template>
			<template #operate="scope">
				<el-button :type="scope.row.isOpen?'danger':'primary'"  size="mini" @click="toggleStatus(scope.row.id)">{{scope.row.isOpen?'关闭':'开启'}}</el-button>
			</template>
		  </global-table>
		</section>
	  </div>
	</div>
  </template>
  <script>
  import GlobalTable from '@/components/GlobalTable';
  import {GetEnterpriseFunctionList,ToggleEnterpriseFunction} from '@/api/enterprise';
  import {guid} from '@/utils/index';
  export default {
	components: { GlobalTable },
	data() {
	  return {
		tabelData: [],
		initData: [
			{
				label: '功能名称',
				value: 'name',
				id: guid(),
				width: 100
			},
			{
				label: '状态',
				value: 'isOpen',
				id: guid(),
				width: 100,
				isCustom:true
			},
		],
		currentPage: 1,
		pageSize: 10,
		totalNum: 0,
		searchValue: '',
	  }
	},
	props:{
		enterpriseId:{
			default:'',
			type:String
		},
		
	},
	created() {
	  this.getDataListFn();
	},
	methods: {
	  currentChange(val) {
		this.currentPage = val;
		this.getDataListFn();
	  },
	  async toggleStatus(id){
		let params = {
			id:this.enterpriseId,
			functionId:id
		}
		let res = await ToggleEnterpriseFunction(params);
		if (res.code === 200) {
			this.$message.success('切换功能状态成功');
			this.getDataListFn();
		} else {
			this.$message.error('切换功能状态失败，错误信息：' + res.erroMessage);
		}
	  },
	  async getDataListFn() {
		let params = {
			id:this.enterpriseId
		}
		let res = await GetEnterpriseFunctionList(params);
		if (res.code === 200) {
			this.tabelData = res.data;
		} else {
			this.tabelData = [];
			this.$message.error('获取员工列表失败，错误信息：' + res.erroMessage);
		}
	  },
	}
  };
  </script>
  
  <style lang="scss" scoped>

  </style>